CPR (cp -R)
There are other modules out there that attempt this, but none did it the way I needed it to be done or they had issues and the author failed to fix them in a timely manner.
Install
npm install cpr
Build Status
Usage
var cpr = require('cpr');
var cpr = require('cpr').cpr;
cpr('/path/from', '/path/to', {
deleteFirst: true,
overwrite: true,
confirm: true
}, function(err, files) {
});
cpr('/path/from', '/path/to', function(err, files) {
});
Options
All options default to false
.
deleteFirst
: Delete the to directory with rimraf
overwrite
: If the destination exists, overwrite itconfirm
: After the copy operation, stat all the files and report errors if any are missingfilter
: RegExp
or function
to test each file against before copying
Filtering
If you give it a RegExp
, it will use that to test
the filename as they are being gathered. If it passes, it will be removed.
If you give it a function
, it will use that with Array.filter
on the list of files.
CLI
cpr
can also be used from the command line which is useful for cross platform support.
Usage:
cpr <source> <destination> [options]
Copies files from source
to destination
.
Options:
-d
, --delete-first
: Delete the destination directory before copying.-f <regex>
, --filter <regex>
: Filter out any items that match <regex>
, a case-insensitive regex pattern.-h
, --help
: Display this usage info.-o
, --overwrite
: Overwrite the destination exists if it exists.-v
, --version
: Display the cpr version.
Note that the CLI's filter
option is simpler than the original NodeJS API, only accepting case-insensitive regular expression patterns and not functions.